﻿@{
    ViewBag.Title = "用户";
    Layout = "~/Views/Shared/_LayoutForEUI.cshtml";
    var listColumns = ViewBag.Columns as List<SGArchiveSystem7x.Models.CColumnsModel>;
    var listRole = ViewBag.Role as List<SGArchiveSystem7x.Models.CComboboxModel>;
    var listDep = ViewBag.Dep as List<SGArchiveSystem7x.Models.CComboboxModel>;
}
<table id="User_Index_grid" class="easyui-datagrid" style="width:100%;" title="@ViewBag.Text0" data-options="
       rownumbers:true,
       singleSelect:false,
       autoRowHeight:false,
       pagination:true,
       fitColumns:true,
       fit:true,
       striped:true,
       checkOnSelect:false,
       selectOnCheck:false,
       collapsible:false,
       toolbar:'#User_Index_tb',
       pageSize: @SGArchiveSystem7x.Models.CCommonsModels.PageSize,
       pageList:[10,15,20]">
    <thead frozen="true">
        <tr>
            @{foreach (var c in listColumns)
                {
                    if (c.Frozen)
                    {
                        <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>
                    }

                }
            }
        </tr>
    </thead>
    <thead>
        <tr>
            @{foreach (var c in listColumns)
                {
                    if (!c.Frozen)
                    {
                        <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>
                    }

                }
            }
        </tr>
    </thead>
</table>
<div id="User_Index_tb" style="padding:2px 5px;">
    <input class="easyui-textbox" type="text" id="txtName" name="txtName" style="width:200px;" label="@ViewBag.Text1" labelwidth="80px" labelalign="right" />
    <select id="cmbStatus" class="easyui-combobox" name="cmbStatus" style="width:200px;" label="@ViewBag.Text2" labelwidth="60px" labelalign="right" editable="false" panelHeight="auto">
        @{
            foreach (var ss in ViewBag.Text3)
            {
                <option value="@ss[0]">@ss[1]</option>
            }
        }
    </select>
    <select id="cmbRole" class="easyui-combobox" name="cmbRole" style="width:200px;" label="@ViewBag.Text4" labelwidth="60px" labelalign="right" editable="false" panelHeight="auto">
        @{foreach (var c in listRole)
            {
                <option value="@c.ID">@c.Text</option>
            }
        }
    </select>
    <div style="display:none">
        <select id="cmbDept" class="easyui-combobox" name="cmbDept" style="width:200px;" label="所属部门:" labelwidth="60px" labelalign="right" editable="false" panelHeight="auto">
            @{foreach (var c in listDep)
            {
                <option value="@c.ID">@c.Text</option>
        }
            }
        </select>
    </div>
    <a href="javascript:void(0);" class="easyui-linkbutton button-blue" iconCls="icon-search" style="width: 90px" onclick="queryUser()">@ViewBag.Text5</a>
    <a href="javascript:void(0);" class="easyui-linkbutton button-blue" iconCls="icon-add" style="width: 90px" onclick="AddUser()">@ViewBag.Text6</a>
</div>
<div id="User_Index_winUser" class="easyui-window" data-options="modal:true,closed:true,iconCls:'icon-save'" minimizable="false" maximizable="false" resizable="false" collapsible="false"
     style="width:500px;height:420px;padding:10px">
    <div style="padding-top:5px">
        <input class="easyui-textbox" labelalign="right" data-options="required:true" style="width:450px" label="@ViewBag.Text7" id="User_User_txtName" />
    </div>
    <div style="padding-top:10px;display:none">
        <input class="easyui-textbox" labelalign="right" data-options="required:true" type="password" style="width:100%" label="@ViewBag.Text8" id="User_User_txtPwd" />
    </div>
    <div style="padding-top:10px">
        <input class="easyui-textbox" labelalign="right" style="width:450px" data-options="required:true" label="@ViewBag.Text9" id="User_User_txtRName" />
    </div>
    <div style="padding-top:10px">
        <input class="easyui-textbox" labelalign="right" style="width:450px" label="@ViewBag.Text10" id="User_User_txtIP" />
    </div>
    <div style="padding-top:10px">
        <select class="easyui-combobox" labelalign="right" style="width:450px" label="@ViewBag.Text11" id="User_User_cmbISIP" editable="false" panelHeight="auto">
            @{
                if (SGArchiveSystem7x.Models.Language._nowLanguage == SGArchiveSystem7xDB._VersionLanguage._Chs)
                {
                    <option value="1">是</option>
                    <option value="0">否</option>
                }
                else
                {
                    <option value="1">Yes</option>
                    <option value="0">No</option>
                }
            }
        </select>
    </div>
    <div style="padding-top:10px;display:none">
        <select class="easyui-combobox" labelalign="right" style="width:450px" label="AD域:" id="User_User_cmbAD" editable="false" panelHeight="auto">
                <option value="1">Yes</option>
               <option value="0">No</option>
        </select>
    </div>
    <div style="padding-top:10px">
        <input class="easyui-textbox" labelalign="right" style="width:450px" label="@ViewBag.Text12" id="User_User_txtPhone" />
    </div>
    <div style="padding-top:10px">
        <input class="easyui-textbox" labelalign="right" validType="email" style="width:450px" label="@ViewBag.Text13" id="User_User_txtEmail" />
    </div>
    <div style="padding-top:10px;display:none">
        <select class="easyui-combobox" labelalign="right" style="width:450px" label="所属部门:" id="User_User_cmbDep" editable="false" panelHeight="auto">
            @{
                foreach (var n in listDep)
                {
                    if (n.ID > -1)
                    {
                        <option value="@n.ID">@n.Text</option>
                    }
                }
            }
        </select>
    </div>
    <div style="padding-top:10px;display:none">
        <select class="easyui-combobox" labelalign="right" style="width:450px" label="部门管理人员:" id="User_User_cmbI01" editable="false" panelHeight="auto">
            <option value="0" selected="selected">否</option>
            <option value="1">是</option>
        </select>
    </div>
    <div style="padding-top:10px">
        <select class="easyui-combobox" labelalign="right" id="User_User_cmbRole" style="width:450px" label="@ViewBag.Text14" editable="false" panelHeight="auto">
            @{
                foreach (var n in listRole)
                {
                    if (n.ID > -1)
                    {
                        <option value="@n.ID">@n.Text</option>
                    }
                }
            }
        </select>
    </div>
    <div style="padding-top:10px">
        <select class="easyui-combobox" labelalign="right" style="width:450px" label="@ViewBag.Text15" id="User_User_cmbStatus" editable="false" panelHeight="auto">
             @{
                if (SGArchiveSystem7x.Models.Language._nowLanguage == SGArchiveSystem7xDB._VersionLanguage._Chs)
                {
                    <option value="1">启用</option>
                    <option value="0">停用</option>
                }
                else
                {
                    <option value="1">Normal</option>
                    <option value="0">No login</option>
                }
            }
        </select>
    </div>
    <input id="User_Index_txtID" hidden="hidden" />
    <div data-options="region:'south',border:false" style="text-align:right;padding-right:20px;margin-top:10px;">
        <a class="easyui-linkbutton button-blue" onclick="Save_User()" data-options="iconCls:'icon-ok'" href="javascript:void(0)" style="width:100px">@ViewBag.Text16</a>
    </div>
</div>
<script>
    var TableDEP=@Html.Raw(Json.Encode(listDep));
    $(document).ready(function () {
        $('#User_Index_grid').datagrid({
            url: '/User/Get_ajaxUserList?rname=&dep=-1&rolename=-1&status=-1',//string rname,string dep,string rolename, int status
            singleSelect: true,
            method: 'post',
            onLoadSuccess: function (data) {
                $('.pagination-page-list').hide();
            }
        });
        InitPagenation();
    });
    ///初始化分页
    function InitPagenation() {
        //设置分页控件
        var p = $('#User_Index_grid').datagrid('getPager');
        $(p).pagination({
            onSelectPage: function (pageNumber, pageSize) {
                SearchPager(pageNumber, pageSize);
            }
        })
    }
    //调用分页方法
    function SearchPager(num, size) {

        $('#User_Index_grid').datagrid('options').url = '/User/Get_ajaxUserListPager?num=' + num +
            '&size=' + size;
        $('#User_Index_grid').datagrid('reload');
        $('#User_Index_grid').datagrid('options').pageNumber = num;
        $('#User_Index_grid').datagrid('options').pageSize = size;
    }

    //查询
    function queryUser() {
        var rname = $('#txtName').val();
        var dep = $('#cmbDept').combobox('getValue');
        var rolename = $('#cmbRole').combobox('getValue');
        var status = $('#cmbStatus').combobox('getValue');
        $('#User_Index_grid').datagrid('options').url = '/User/Get_ajaxUserList?rname=' + rname + '&dep=' + dep + '&rolename=' + rolename + '&status=' + status;
        $('#User_Index_grid').datagrid('load');
    }
    //添加、修改
    function Save_User() {
        var text = $('#User_Index_winUser').panel('options').title;
        var id = $('#User_Index_txtID').val();
        var uname = $('#User_User_txtName').val();
        var ip = $('#User_User_txtIP').val();
        var pwd = $('#User_User_txtPwd').val();
        var rname = $('#User_User_txtRName').val();
        var ad = $('#User_User_cmbAD').combobox('getValue');
        var ISIP = $('#User_User_cmbISIP').combobox('getValue');
        var phone = $('#User_User_txtPhone').val();
        var email = $('#User_User_txtEmail').val();
        var dep = $('#User_User_cmbDep').combobox('getValue');
        var role = $('#User_User_cmbRole').combobox('getValue');
        var status = $("#User_User_cmbStatus").combobox('getValue');
        var i01 = $("#User_User_cmbI01").combobox('getValue');
        if (uname == "") {
            $.messager.alert('@ViewBag.Text17', '@ViewBag.Text32', 'error');
            return false;
        }
        if (rname == "") {
            $.messager.alert('@ViewBag.Text17', '@ViewBag.Text33', 'error');
            return false;
        }
        //if (i01 == 1 && email == "") {
       //     $.messager.alert('@ViewBag.Text17', '部门管理人员必须填写邮箱!', 'error');
       //     return;
       // }
        else {
            
            if (text == '@ViewBag.Text26') {
                $.ajax({
                    url: "/User/Get_ajaxUserAdd",
                    dataType: "text",
                    method: "post",
                    data: {
                        uname: uname, rname: rname, pwd: pwd, ip: ip, ad: ad, ISIP: ISIP, phone: phone, email: email, role: role, dep: dep, status: status, i01: i01
                    },
                    success: function (data) {
                        if (data == '0')
                            $.messager.alert('@ViewBag.Text17', '@ViewBag.Text25', 'warning');
                        else if (data == '2')
                            $.messager.alert('@ViewBag.Text17', '@ViewBag.Text19', 'error');
                        else
                            $.messager.alert('@ViewBag.Text17', '@ViewBag.Text18', 'info');
                        $('#User_Index_winUser').window('close');
                        $('#User_Index_grid').datagrid('reload');
                        $('#User_User_txtName').textbox('setValue', '');
                        $('#User_User_txtIP').textbox('setValue', '');
                        $('#User_User_txtRName').textbox('setValue', '');
                        $('#User_User_txtPhone').textbox('setValue', '');
                        $('#User_User_txtEmail').textbox('setValue', '');
                    }
                })
            }
            else {
                $.ajax({
                    url: "/User/Get_ajaxUserModify",
                    dataType: "text",
                    method: "post",
                    data: {
                        id: id, uname: uname, rname: rname, pwd: pwd, ip: ip, ad: ad, ISIP: ISIP, phone: phone, email: email, role: role, dep: dep, status: status, i01: i01
                    },
                    success: function (data) {
                        if (data == '0')
                            $.messager.alert('@ViewBag.Text17', '@ViewBag.Text25', 'warning');
                        else if (data == '2')
                            $.messager.alert('@ViewBag.Text17', '@ViewBag.Text19', 'error');
                        else
                            $.messager.alert('@ViewBag.Text17', '@ViewBag.Text18', 'info');
                        $('#User_Index_winUser').window('close');
                        $('#User_Index_grid').datagrid('reload');
                        $('#User_User_txtName').textbox('setValue', '');
                        $('#User_User_txtIP').textbox('setValue', '');
                        $('#User_User_txtRName').textbox('setValue', '');
                        $('#User_User_txtPhone').textbox('setValue', '');
                        $('#User_User_txtEmail').textbox('setValue', '');
                    }
                });
            }
        }
    }

    function AddUser() {
        $('#User_Index_winUser').window({
            title: '@ViewBag.Text26',
            closed: false,
            height: 420
        });
    }

    function Edit_User(id) {
        $.ajax({
            method: 'post',
            dataType: 'Json',
            data: { id: id },
            url: '/User/Get_ajaxUserId',
            success: function (data) {
                $('#User_Index_txtID').val(data.U_ID);
                $('#User_User_txtName').textbox('setValue', data.U_NAME);
                $('#User_User_txtPwd').textbox('setValue', data.U_PWD);
                $('#User_User_txtRName').textbox('setValue', data.U_RNAME);
                $('#User_User_cmbSex').combobox('setText', data.U_V03)
                $('#User_User_txtPhone').textbox('setValue', data.U_V04);
                $('#User_User_txtEmail').textbox('setValue', data.U_V01);
                $('#User_User_cmbDep').combobox('setValue', data.U_DEPID)
                $('#User_User_cmbRole').combobox('setValue', data.U_ROLEID)
                $("#User_User_cmbStatus").combobox('setValue', data.U_STATUS)
                $('#User_User_txtIP').textbox('setValue', data.U_IP);
                $('#User_User_cmbAD').combobox('setValue',data.U_AD);
                $('#User_User_cmbISIP').combobox('setValue', data.U_ISIP);
                $('#User_User_cmbI01').combobox('setValue', data.U_I01);
                $('#User_Index_winUser').window({
                    title: '@ViewBag.Text27',
                    closed: false,
                    height: 420
                });
            }
        })
    }
    function formatStatus(value, row) {
        if (value == '0')
            return "<span style='color:red'>@ViewBag.Text29</span>";
        else
            return "<span style='color:blue'>@ViewBag.Text28</span>"
    }
    function formatAD(value, row) {
        if (value == '0')
            return "@ViewBag.Text31";
        else
            return "@ViewBag.Text310";
    }


    function formatIP(value, row) {
        if (value == '0')
            return "@ViewBag.Text31";
        else
            return "@ViewBag.Text310";
    }

    function Reset_Pwd(id, uad) {
        if (uad == 1)
        {
            $.messager.alert('@ViewBag.Text17', 'ad域登录用户没有密码!', 'info');
            return false;
        }
        var pwd = "123456";
        $.messager.confirm("@ViewBag.Text17", "@ViewBag.Text22", function (r) {
            if (r) {
                $.ajax({
                    method: 'post',
                    dataType: 'Json',
                    data: { id: id, pwd: pwd },
                    url: '/User/Get_ajaxResetPwd',
                    success: function (data) {
                        if (data == 1) {
                            $.messager.alert('@ViewBag.Text17', '@ViewBag.Text23', 'info');
                        }
                        else
                            $.messager.alert('@ViewBag.Text17', '@ViewBag.Text24', 'error');
                    }
                })
            }
        })
    }
    function formatDep(value, row) {
        for (var i = 0; i < TableDEP.length; i++) {
            if (TableDEP[i].ID == value) {
                return TableDEP[i].Text;
            }
        }
    }
    function formatEdit(value, row) {
        var id = row["U_ID"];
        return "<a href='javascript:void(0)' onclick='Edit_User(" + id + ")'><img src='../Content/images/edit.png'></img>" + '@ViewBag.Text20' + "</a>";
    }
    function formatReset(value, row) {
        var id = row["U_ID"];
        var uad = row.U_AD;
        return "<a href='javascript:void(0)' onclick='Reset_Pwd(" + id + "," + uad + ")'><img src='../Content/images/text_edit.png'></img>" + '@ViewBag.Text21' + "</a>";

    }
    function formatDate(value, row) {
        if (value != null) {
            var time = new Date(parseInt(value.substr(6, 19)))//.toLocaleDateString();//13
            return time.getFullYear() + "-" + (time.getMonth() + 1) + "-" + time.getDate() + " " + time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds();
        }
        else {
            return "";
        }
    }
    ///初始化分页
    function InitPagenation() {
        //设置分页控件
        var p = $('#User_Index_grid').datagrid('getPager');
        $(p).pagination({
            onSelectPage: function (pageNumber, pageSize) {
                QueryPager(pageNumber, pageSize);
            }
        });
    }
    ///分页查询
    function QueryPager(num, size) {
        $('#User_Index_grid').datagrid('options').url = '/User/Get_ajaxUserListPager?num=' + num + '&size=' + size;
        $('#User_Index_grid').datagrid('reload');
        $('#User_Index_grid').datagrid('options').pageNumber = num;
        $('#User_Index_grid').datagrid('options').pageSize = size;
        return;
    }
</script>
